package com.yunsc.store.controller;

import com.yunsc.common.utils.Result;
import com.yunsc.module.dto.LoginParamsDto;
import com.yunsc.module.dto.StoreDataDto;
import com.yunsc.module.entity.YunscStoreEntity;
import com.yunsc.service.YunscStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-04-04 22:00
 */
@Api(value = "StoreController", tags = "商家信息接口")
@Slf4j
@RestController()
@RequestMapping("store")
public class StoreController {

    @Resource
    private YunscStoreService storeService;
    Integer storeId = 10001;


    @GetMapping("/store/data")
    public Result storeData() {
        StoreDataDto data = storeService.queryStoreData(storeId);
        Map<String, Object> map = new HashMap<>();
        map.put("data", data);
        return Result.ok(map);
    }

    @GetMapping("/store/info")
    public Result storeInfo() {
        YunscStoreEntity storeEntity = storeService.queryStoreInfo(storeId);
        Map<String, Object> map = new HashMap<>();
        map.put("storeInfo", storeEntity);
        return Result.ok(map);
    }


    @ApiOperation(value = "登录", notes = "登录参数: username, password", httpMethod = "POST")
    @PostMapping(value = "/passport/login")
    public Result login(@Validated @RequestBody LoginParamsDto params) {
        String username = params.getUsername();
        String password = params.getPassword();
        if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
            return Result.error("请输入用户名和密码");
        }

        Map<String, Object> map = new LinkedHashMap<>();
        map.put("token", "token345657643221");
        map.put("userId", "10001");
        return Result.ok(map);
    }


    @PostMapping(value = "/passport/logout")
    public Result logOut(HttpServletRequest req, HttpServletResponse resp) {
        return Result.ok();
    }
}
